//
//  ContentView.swift
//  Monujo
//
//  Created by user on 2023/12/28.
//

import SwiftUI
import SwiftData


struct ContentView: View {
    @Query var networths: [NetWorth]
    @Query var wallets: [Wallet]
    @State private var isImportViewPresented = false
    @Environment(\.modelContext) var modelContext
    
    
    var body: some View {
        NavigationStack {
            if networths.count > 0 {
                Text(networths[0].name)
            } else {
                Text("0.0")
            }
            List {
                ForEach(wallets) { wallet in
                    VStack(alignment: .leading) {
                        Text(wallet.name).font(.headline)
                    }
                }
            }
            .navigationTitle("Monujo")
            .toolbar{
                Button("Add Wallet", action: addWallet)
            }
        }
    }
    
    func addWallet() {
        let wallet1 = Wallet(name: "first wallet")
        modelContext.insert(wallet1)
    }
}


#Preview {
    ContentView()
}
